package org.uned.agonzalo16.bitacora.web.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.uned.agonzalo16.bitacora.dao.ArticleDao;
import org.uned.agonzalo16.bitacora.domain.Blog;

@Configurable
@SuppressWarnings("serial")
public class ArticlesByBlogTag extends TagSupport {

	private String var;
	private transient Blog blog;

	@Autowired
	private transient ArticleDao articleDao;

	public void setVar(String var) {
		this.var = var;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	@Override
	public int doStartTag() throws JspException {

		pageContext.setAttribute(var, articleDao.findByBlog(blog));
		return SKIP_BODY;
	}
}
